//
//  AppTools.m
//  豆瓣
//
//  Created by dllo on 15/12/18.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "AppTools.h"
#import "AFNetworking.h"
@implementation AppTools
//AFN封装
+ (void)finalAFNWithURLString:(NSString *)url parameters:(NSDictionary *)parameters successAFNBlock:(AFNBlock)block
{
    //请求管理对象
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    //设置请求数据格式和安全
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json", @"text/plain", @"text/html", nil];
    
    manager.securityPolicy.allowInvalidCertificates = YES;
    
    //根据请求参数是否为空，判断使用GET还是POST
    if (parameters) {
        [manager POST:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            
            //请求成功
            block(responseObject);
            
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"%@", error);
        }];
    } else {
        [manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            block(responseObject);
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"%@", error);
        }];
    }
    
}
@end
